from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
import time




class Base():

    def __init__(self, driver):
        self.driver = driver
        # self.driver = webdriver.Edge()

    def open_url(self, url):
        self.driver.get(url)

    def time(self, name):
        t = time.strftime('%Y%m%d%H%M%S', time.localtime())
        self.driver.save_screenshot(t+name)

    def find_element(self, loc):
        try:
            # WebDriverWait(self.driver, 20, 0.5).until(lambda driver: driver.find_element(*loc).isdisplayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
            self.time('error.png')

    def click(self, loc):
        self.find_element(loc).click()

    def send_keys(self, loc, info):
        self.find_element(loc).send_keys(info)

    def accept_alert(self):
        alert = self.driver.switch_to.alert
        alert.accept()

    def dismiss_alert(self):
        alert = self.driver.switch_to.alert
        text_info = alert.text
        alert.dismiss()
        return text_info








